import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: BasicAnimatedIconExample());
  }
}

class BasicAnimatedIconExample extends StatefulWidget {
  @override
  _BasicAnimatedIconExampleState createState() =>
      _BasicAnimatedIconExampleState();
}

class _BasicAnimatedIconExampleState extends State<BasicAnimatedIconExample>
    with SingleTickerProviderStateMixin {
  late AnimationController _animationController;
  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 400),
    );
  }

  @override
  void dispose() {
    super.dispose();
    _animationController.dispose();
  }

  bool isPlay = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('基础 AnimatedIcon')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            AnimatedIcon(
              icon: AnimatedIcons.event_add,
              progress: _animationController,
              size: 60,
            ),

            ElevatedButton(
              onPressed: () {
                setState(() {
                  isPlay = !isPlay;

                  if (isPlay) {
                    _animationController.forward(from: 0);
                  } else {
                    _animationController.reverse();
                  }
                });
              },
              child: Text(isPlay ? '暂停' : '播放'),
            ),
          ],
        ),
      ),
    );
  }
}
